using System;
using System.Collections.Generic;

using GymManager.Exception;
using GymManager.Persistence.VO;

using IBatisNet.DataMapper;

using log4net;

namespace GymManager.Persistence.DAO
{
    /// <summary>
    /// Class responsible by getting information from database about version history
    /// </summary>
    public class VersionHistoryDAO
    {
        // logger instance
        private ILog _logManager = LogManager.GetLogger(typeof(VersionHistoryDAO));

        /// <summary>
        /// Method responsible by returning all versions history 
        /// </summary>
        /// <returns>IList - List of All Version History</returns>
        /// <see cref="GymManager.Exception.PersistenceException"/>
        public IList<VersionHistory> findAll()
        {
            if (_logManager.IsInfoEnabled)
            {
                _logManager.Info("Begin Method");
            }

            // list to be returned
            IList<VersionHistory> versionHistoryList = null;

            try
            {
                ISqlMapper ibatisMapper = DAOManager.getInstance();
                versionHistoryList = ibatisMapper.QueryForList<VersionHistory>("VersionHistory.findAll", null);
            }
            catch(System.Exception ex)
            {
                _logManager.Error("Problems to find information about Version History", ex);
                throw new PersistenceException("Problems to find information about Version History", ex);
            }
            
            if (_logManager.IsInfoEnabled)
            {
                _logManager.Info("End Method");
            }

            return versionHistoryList;
        }
    }
}
